package cn.txun05.csmall.commons.web;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;


@Data
@Accessors(chain = true)
public class JsonResult implements Serializable {
    @ApiModelProperty("业务状态码")
    private Integer state;
    @ApiModelProperty("业务描述")
    private  String message;
    @ApiModelProperty("业务数据")
    private Object data;

    public JsonResult() {

    }

    public static JsonResult ok(){
        return ok(null);
    }
    public static JsonResult ok(Object data){
        JsonResult jsonResult  = new JsonResult();
        jsonResult.setState(ServiceCode.OK.getValue());
        jsonResult.setData(data);
        return jsonResult;
    }

    public static JsonResult fail(ServiceCode serviceCode,String message){
        JsonResult jsonResult  = new JsonResult();
        jsonResult.setState(serviceCode.getValue());
        jsonResult.setMessage(message);
        return jsonResult;
    }

    public JsonResult(Integer state, String message) {
        this.state = state;
        this.message = message;
    }


    /*public JsonResult setState(Integer state) {
        this.state = state;
        return this;
    }

    public JsonResult setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public Integer getState() {
        return state;
    }*/


}
